package ch.idsia.ai.agents.controllers.myai.tests;

import ch.idsia.ai.agents.controllers.myai.MyAI;
import ch.idsia.maibe.tasks.BasicTask;
import ch.idsia.tools.CmdLineOptions;
import org.junit.*;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

/**
 * Created by IntelliJ IDEA.
 * User: Blake
 * Date: Jul 1, 2010
 * Time: 8:26:44 PM
 * To change this template use File | Settings | File Templates.
 */
public class MyAITest
{
    private class TestBasicTask extends BasicTask
    {
        public TestBasicTask()
        {
            super(null);
        }
        public TestBasicTask(CmdLineOptions cmdLineOptions)
        {
            super(cmdLineOptions);
        }

        public boolean[] runTestEpisode()
        {
            environment.tick();
            agent.integrateObservation(environment);

            boolean[] action = agent.getAction();
            environment.performAction(action);
            return action;
        }

        public boolean finished()
        {
            return environment.isLevelFinished();
        }
    }
    @Test public void testMyAI()
    {
        MyAI test = new MyAI();
        assertNotNull("testMyAI", test);
    }

    @Test   public void testGetAction()
    {

        String[] args = {"-ag", "ch.idsia.ai.agents.controllers.myai.MyAI", "-fps", "100", "-vis", "off"};
        CmdLineOptions options = new CmdLineOptions(args);
        TestBasicTask task = new TestBasicTask(options);

        for(int i = 0; i < 100; ++i)
        {
            task.reset(options);

            while(!task.finished())
            {
                boolean[] action = task.runTestEpisode();
                boolean isNull = true;
                for (boolean j : action)
                {
                    if (j)
                        isNull = true;
                }
                assertTrue("testGetAction", isNull);
            }
        }
    }
}
